<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-4-6
 * Time: 下午2:02
 * 融云短信发送
 */
if (! defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('ry_sms_msg')) {
    function ry_sms_msg($code) {
        $arr = array(
            1009 => '没有开启图验功能',
            1010 =>	'未使用已开启的图验功能',
            1000 =>	'内部逻辑错误	',
            1003 =>	'参数错误',
            1005 =>	'参数长度超出限制',
            1008 =>	'调用超过频率上限',
            1002 =>	'缺少参数',
            1004 =>	'验证签名错误',
            1050 =>	'内部服务响应超时',
            1012 =>	'图片验证码不正确',
            1011 =>	'剩余条数不足，需要充值',
            1013 =>	'短信通道不可用',
            1014 =>	'短信验证码已验证过，再次验证失效',
            1015 =>	'短信验证码过期无效',
            200 =>	'发送成功',
        );
        return $arr[$code];
    }
}
if (!function_exists('ry_getImageCode')) {
    function ry_getImageCode() {
        include LIBS_PATH.'ry/rongcloud.php';
        $RongCloud = new RongCloud(RY_APPKEY,RY_APPSECRET);
        $result = $RongCloud->yrSMS()->getImageCode(RY_APPKEY);
        return $result;
    }
}
if (!function_exists('ry_sendCode')) {
    function ry_sendCode($phone,$templateId) {
        include LIBS_PATH.'ry/rongcloud.php';
        $RongCloud = new RongCloud(RY_APPKEY,RY_APPSECRET);
        $result = $RongCloud->yrSMS()->sendCode($phone, $templateId);
        return $result;
    }
}
if (!function_exists('ry_sendNotify')) {
    function ry_sendNotify($phone,$templateId,$p1='',$p2='',$p3='') {
        include LIBS_PATH.'ry/rongcloud.php';
        $RongCloud = new RongCloud(RY_APPKEY,RY_APPSECRET);
        $result = $RongCloud->yrSMS()->sendNotify($phone, $templateId,$p1,$p2,$p3);
        return $result;
    }
}
/**
 * 验证码验证方法
 *
 * @param  sessionId:短信验证码唯一标识，在发送短信验证码方法，返回值中获取。（必传）
 * @param  code:短信验证码内容。（必传）
 *
 * @return $json
 **/
if (!function_exists('ry_verifyCode')) {
    function ry_verifyCode($sessionId, $code) {
        include LIBS_PATH.'ry/rongcloud.php';
        $RongCloud = new RongCloud(RY_APPKEY,RY_APPSECRET);
        $result = $RongCloud->yrSMS()->verifyCode($sessionId, $code);
        return $result;
    }
}
if (!function_exists('ry_verifyCode')) {
    function ry_sms_log($data) {
        switch($data['type']) {
            case 1:
                $msg = '用户注册';//注册
                break;
            case 2:
                $msg = '密码找回';//密码找回
                break;
            case 3:
                $msg = '修改密码';//修改密码
                break;
        }
        $CI =& get_instance();
        $CI->load->model('sms_log_model');
        $sms_log_data = array(
            'phone'=> $data['phone'],
            'ip'=> get_ip(),
            'content'=> $msg,
            'status'=> $data['code'],
            'code'=> '',
            'msg'=> $data['ry_msg'],
            'time'=> time(),
        );
        $CI->sms_log_model->create($sms_log_data);
    }
}
